package com.ytf.test.third;

/**
 * @author: YTF
 * @date: 2024/9/12 14:24
 * @version: 1.0
 * @description: 狗
 */
public class Dog {

    String name;
    String says;

    public static void main(String[] args) {
        Dog dog1 = new Dog();
        dog1.name="spot";
        dog1.says="Ruff!";
        Dog dog2 = new Dog();
        dog2.name="scruffy";
        dog2.says="Wurf!";
        System.out.println(dog1);
        System.out.println(dog2);
        Dog dog3 = dog1;
        System.out.println(dog3 == dog1);
        System.out.println(dog3.equals(dog1));
        System.out.println(dog1 == dog2);
        System.out.println(dog1.equals(dog2));
        /**
         * output
         * Dog{name='spot', says='Ruff!'}
         * Dog{name='scruffy', says='Wurf!'}
         * true
         * true
         * false
         * false
         * 总结：
         *  实体直接不能直接比较 默认比较引用地址 比较实体数据需要重写equals方法
         */
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", says='" + says + '\'' +
                '}';
    }
}
